home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / inventor / www / workarounds / MFNode.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  1.5 KB  |  68 lines

  1. //
  2. // This is a patch for the Inventor 2.0 SoMFNode field, which can core
  3. // dump when its values are deleted.
  4. //
  5. // To apply this patch, compile this file into a .o and then link
  6. // the .o before -lInventor.  The linker may give a warning.
  7. // This is normal and expected.
  8. //
  9.  
  10. #include <Inventor/SoDB.h>
  11. #include <Inventor/nodes/SoNode.h>
  12. #include <Inventor/fields/SoMFNode.h>
  13.  
  14. ////////////////////////////////////////////////////////////////////////
  15. //
  16. // This overrides the definition in SO_MFIELD_ALLOC_SOURCE() to
  17. // keep track of references and auditors.
  18. //
  19. ////////////////////////////////////////////////////////////////////////
  20.  
  21. void
  22. SoMFNode::allocValues(int newNum)
  23. {
  24.     int    i;
  25.  
  26.     if (values == NULL)    {
  27.     if (newNum > 0) {
  28.         values = new SoNode * [newNum];
  29.  
  30.         // Make sure all pointers are initialized to NULL
  31.         for (i = 0; i < newNum; i++)
  32.         values[i] = NULL;
  33.     }
  34.     }
  35.     else {
  36.     SoNode    **oldValues = values;
  37.  
  38.     if (newNum > 0) {
  39.         values = new SoNode * [newNum];
  40.         for (i = 0; i < num && i < newNum; i++)
  41.         values[i] = oldValues[i];
  42.  
  43.         // Initialize unused pointers to NULL
  44.         for (i = num; i < newNum; i++)
  45.         values[i] = NULL;
  46.     }
  47.     else
  48.         values = NULL;
  49.  
  50.     // Free up any old stuff
  51.     if (oldValues != NULL) {
  52.  
  53.         // Remove auditors and references on unused values
  54.         for (i = newNum; i < num; i++) {
  55.         if (oldValues[i] != NULL) {
  56.             oldValues[i]->removeAuditor(this, SoNotRec::FIELD);
  57.             oldValues[i]->unref();
  58.         }
  59.         }
  60.  
  61.         delete [] oldValues;
  62.     }
  63.     }
  64.  
  65.     num = maxNum = newNum;
  66. }
  67.  
  68.